package SMSGUI;

import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.table.*;
import SocialMediaSentiment.writeExcel;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.util.HashMap;
import jxl.write.WriteException;


public class ScrollableJTable{
  public static void main(String[] args) {
  new ScrollableJTable();
  }
  public ScrollableJTable(){
 

  
  }
  public static void table(final String[][]data, final HashMap<Integer, String[]>excelData){
  Toolkit toolkit = Toolkit.getDefaultToolkit();
  final Dimension scrnsize = toolkit.getScreenSize();
  JFrame frame = new JFrame();
  JPanel panel = new JPanel();
  //final String data[][] = {{"tweet","1"},{"tweet","2"},{"tweet","3"},{"tweet","4"},{"tweet","5"}};
  
  frame.setBounds(0, 300, 900,scrnsize.height-300);
  System.out.println(data.length);
  String col[] = {"index","tweet","sentiments"};
  final JTable table = new JTable(data,col);
  System.out.println(table.getColumnCount());
  JTableHeader header = table.getTableHeader();
  header.setBackground(Color.yellow);
  JScrollPane pane = new JScrollPane(table);
  table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
  
  TableColumn firstColumn = table.getColumnModel().getColumn(1);
  int width = 800;
  firstColumn.setPreferredWidth(width);
  
  pane.setPreferredSize(new Dimension(800,scrnsize.height-300));
  
  Container content = frame.getContentPane();
  content.setBackground(Color.white);
  
  
  
  JButton saveButton = new JButton();
  saveButton.setLayout(new BorderLayout());
  saveButton.setText("<html>S<br>a<br>v<br>e</html>");
  saveButton.setBounds(3,200,38,100);
  //pane.setBounds(0,200,800,scrnsize.height-300);
  saveButton.addActionListener(new ActionListener() {
		   public void actionPerformed(ActionEvent e) {
			   int rows = table.getRowCount();
			   
			   HashMap<Integer,String[]> map = new HashMap<Integer,String[]>();
			   HashMap<String,String> mapFuckedUP = new HashMap<String,String>();
			   for(int i=0;i<rows;i++){
				   
				  
				   String tweet = data[i][0];
				   String sentiment = (String) table.getModel().getValueAt(i, 2);
				   String index = (String) table.getModel().getValueAt(i, 0);
				   String[] result = new String[2];
				   result[0] = tweet;
				   result[1] = sentiment; 
				   map.put(Integer.parseInt(index), result);
				   mapFuckedUP.put(tweet, sentiment);
//				   try {
//					NaiveBayes.updateCounters(map);
//					writeExcel.write("newFIle.xls", mapFuckedUP);
				   
					
//				} catch (WriteException | IOException e1) {
//					// TODO Auto-generated catch block
//					e1.printStackTrace();
//				}
				   
				   
				   
				   
			   }
			   Picture.createPicture(map, excelData);
		   }
  });
  //table.getModel().getValueAt(arg0, arg1);  
	content.add(saveButton);
	  content.add(panel);
  panel.add(pane);
  frame.add(panel);
  //frame.setSize(600,600);
  frame.setUndecorated(true);
  frame.getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG);
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.setVisible(true);

  
  }
  
  
  
}